package com.xuyiwei.mayi;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by xuyiwei on 2019/4/16.
 */
public class HttpClientServlet extends HttpServlet {
    private int i = 1;

    public HttpClientServlet() {
        System.out.println("servlet构造方法");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setHeader("Access-Control-Allow-Origin","*");

        String id = req.getParameter("id");
        if("1".equals(id)){
            System.out.println("id是1的数据");
            resp.getWriter().write("id是1的数据,11111");
        }else{
            resp.getWriter().write("id不是1的数据,222222");
        }
    }

    @Override
    public void destroy() {
        System.out.println("servlet已经被销毁");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("servlet的init方法");
    }
}
